package com.tanhua.server.contoller;

import com.tan.model.vo.PageResult;
import com.tan.model.vo.UserInfoVo;
import com.tanhua.server.service.HuanxinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {
    @Autowired
    private HuanxinService huanxinService;
    @GetMapping("/userinfo")
    public ResponseEntity<UserInfoVo> searchUserInfo(String huanxinId) {
      UserInfoVo userInfoVo =    huanxinService.searchUserInfo(huanxinId);
      return ResponseEntity.ok(userInfoVo);

    }
    @PostMapping("/contacts")
    public ResponseEntity addContact(@RequestBody Map map) {
        Long userId =Long.valueOf (map.get("userId").toString());
        huanxinService.addFriend(userId);
        return ResponseEntity.ok(null);
    }
    @GetMapping("/contacts")
    public ResponseEntity searchFriend(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer pagesize,String keyword) {
       PageResult pageResult = huanxinService.searchFriend(page,pagesize,keyword);
       return ResponseEntity.ok(pageResult);


    }
    @GetMapping("/likes")
    public ResponseEntity getLikeCount(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer pagesize) {
        PageResult pageResult = huanxinService.getLikeCount(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }
    @GetMapping("/comments")
    public ResponseEntity<PageResult> getcommentCount(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pageResult = huanxinService.getcommentCount(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }
    @GetMapping("/loves")
    public ResponseEntity getLoveCount(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer pagesize) {
        PageResult pageResult = huanxinService.getLoveCount(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }
    @GetMapping("/announcements")
    public ResponseEntity messageCount(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer pagesize) {
        PageResult pageResult = huanxinService.announcementsCount(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

}
